let VALID_KEYS = [
  // status
  "loginValidatedEmail",
  "inForgoting",
  "inReseting",
  
  // token
  "resetPasswordToken",
  "emailVerificationToken",
  "emailVerificationSuccess",

  // message
  "errorMessage",
  "infoMessage",

  // dialog
  "accountsDialogContent"
];

let validateKey = function(key) {
  if ($.inArray(key, VALID_KEYS) < 0) throw new Error("无效的键名：" + key);
};

let KEY_PREFIX = "class.accounts.";

const AccountsSession = {
  set: function(key, value) {
    validateKey(key);
    this._set(key, value);
  },

  _set: function(key, value) {
    Session.set(KEY_PREFIX + key, value);
  },

  get: function(key) {
    validateKey(key);
    return Session.get(KEY_PREFIX + key);
  },

  // content
  accountsDialogContent: function(content = "accounts_login") {
    this.resetMessage();
    this._set("loginValidatedEmail", false);
    this._set("accountsDialogContent", content);
  },

  // message
  errorMessage: function(message) {
    this._set("errorMessage", message);
    this._set("infoMessage", null);
  },

  infoMessage: function(message) {
    this._set("errorMessage", null);
    this._set("infoMessage", message);
  },

  resetMessage: function() {
    this._set("errorMessage", null);
    this._set("infoMessage", null);
  },

  clear: function() {
    this.resetMessage();
    this._set("resetPasswordToken", null);
    this._set("loginValidatedEmail", false);
    this._set("onForgotFlow", false);
    this._set("accountsDialogContent", "");
  }
};

export default AccountsSession;
